package com.shujia.common_util.four;


import org.junit.Test;

public class StingDemo2 {


    @Test
    public void test2() {
        String s1 = "abc";
        for (int i = 0; i < 10000; i++) {
            s1 += "1724731843";
        }
        System.out.println(s1);
    }

    @Test
    public void test1() {
        String s1 = "hello";
        String s2 = "world";
        String s3 = new String("hello");
        String s4 = "hello" + "world";// 指向常量池
        String s5 = "helloworld";
        String s6 = s1 + "world";// 堆内存
        String s7 = (s1 + s2).intern();// 指向常量池
        String s8 = "hello" + s2;// 堆内存

        System.out.println(System.identityHashCode(s1));
        System.out.println(System.identityHashCode(s2));
        System.out.println(System.identityHashCode(s3));
        System.out.println(System.identityHashCode(s4));
        System.out.println(System.identityHashCode(s5));
        System.out.println(System.identityHashCode(s6));
        System.out.println(System.identityHashCode(s7));
        System.out.println(System.identityHashCode(s8));
    }

}
